
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div#container{width:500px}
div#header {background-color:#99bbbb;}
div#menu {background-color:#ffff99;width:150px;float:left;}
div#content {background-color:#EEEEEE;width:1000px;}
div#footer {background-color:#99bbbb;clear:both;text-align:center;}
h1 {margin-bottom:0;}
h2 {margin-bottom:0;font-size:18px;}
ul {margin:0;}
li {list-style:none;}
</style>
</head>

<body>

<div id="container">

<div id="header">
<h1>ノート閲覧ページ</h1>
</div>



<div id="content">

 
<script language="JavaScript" type="text/javascript">   

var subject2=[
["負の数","整数","数Ⅲ","数Ⅱ","代数"],   
["現代文","古典","漢文"],   
["文法","単語"],
["物理","化学","生物"],
["日本史","倫理","公民","現代社会","世界史"],    
];

function getSubject2(){   
  
var sltSubject1=document.form1.subject1;   
  
var sltSubject2=document.form1.subject2;   

var subject12=subject2[sltSubject1.selectedIndex - 1];   
 
sltSubject2.length=1;   
 
for(var i=0;i<subject12.length;i++){   
	sltSubject2[i+1]=new Option(subject12[i],subject12[i]);   
}   
}
</script>   

 
<FORM METHOD=POST ACTION="see.php" name="form1"> 
<div id="menu">
<h2>
   <select name="self"> 
    <option value="科目">科目</option>
    <option value="自分">自分</option>
  </select>
</h2>

</div>  
<SELECT NAME="subject1" onChange="getSubject2()">
<OPTION VALUE="選択してください">選択してください</OPTION>
<OPTION VALUE="数学">数学</OPTION>   
<OPTION VALUE="国語">国語</OPTION>   
<OPTION VALUE="英語">英語</OPTION>   
<OPTION VALUE="理科">理科</OPTION>   
<OPTION VALUE="社会">社会</OPTION>
 
</SELECT>   
<SELECT NAME="subject2">
</SELECT>

<input type="submit" value="送信する">   
</FORM>
<?php
if($_POST["self"]=="自分"){
	session_start();
	mysql_set_charset('utf8');

	$dbh = new PDO('mysql:dbname=orb;host=localhost', 'root', '');

	$array="";
	if($_POST['subject1']!="選択してください"){
		$sql = "select FileName,Point from orb.Notes where UserName='".$_SESSION["UserName"]."' and Subject='".$_POST['subject1']."' and Content='".$_POST['subject2']."'";
		$array=$dbh->query($sql);
		print "<h1>".$_SESSION["UserName"]."の".$_POST['subject1']." ".$_POST['subject2']."投稿ノート";
	}else{
		$sql = "select FileName,Point from orb.Notes where UserName='".$_SESSION["UserName"]."'";
		$array=$dbh->query($sql);
		print "<h1>".$_SESSION["UserName"]."の投稿ノート</h1><br>";
	}

	foreach($array as $row){
		print "<h2>点数:".$row["Point"]."</h2><br>";
		print "<img src='notes/".$row["FileName"]."' width='750px' height='450px'><br><br>";
	}
	$dbh=null;
}elseif($_POST['subject1']!="選択してください"){
	session_start();
	mysql_set_charset('utf8');
	$subject=$_POST['subject1'];
	$content=$_POST['subject2'];
	
	$dbh = new PDO('mysql:dbname=orb;host=localhost', 'root', '');

	$sql = "select FileName,Point,UserName from orb.Notes where Subject='".$subject."'and Content='".$content."' order by Point desc";
	$array=$dbh->query($sql);

	print "<h1>".$subject." ".$content."ランキング</h1><br>";

	$counter=0;
	foreach($array as $row){
		$nickname="";
		$sql="select NickName from orb.Accounts where UserName='".$row["UserName"]."'";
		$getter=$dbh->query($sql);
		foreach($getter as $row2){
			$nickname=$row2['NickName'];
		}
		
		print "<h2>".($counter+1)."位 点数:".$row["Point"]." 投稿者".$nickname."</h2><br>";
		print "<img src='notes/".$row["FileName"]."' width='750px' height='450px'><br><br>";
		$counter=$counter+1;
		if($counter==5) break;
	}
	$dbh=null;
}


?>

</div>
<div id="footer">Copyright noweb</div>

</body>
</html>